package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class TipoVariavelProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static TipoVariavelProduction instance = new TipoVariavelProduction();

    public static TipoVariavelProduction getInstance() {
        return instance;
    }


    /**
     * Regra: tipo_variavel : tipo_primitivo | IDENTIFIER;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (TipoPrimitivoProduction.getInstance().analyze(st, et)) {
            return true;
        }
        if (basicParse(st, TokenClass.IDENTIFIER)) {
            return true;
        }
        return false;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.IDENTIFIER);
        first.add(TokenClass.KEYWORD_INTEIRO);
        first.add(TokenClass.KEYWORD_REAL);
        first.add(TokenClass.KEYWORD_LOGICO);
        first.add(TokenClass.KEYWORD_CARACTERE);
        first.add(TokenClass.KEYWORD_STRING);
    }

    @Override
    protected void populateFollow() {

        //from TipoRetornoF
        follow.add(TokenClass.DELIMITER_OPENING_SQUARE_BRACKET);
        follow.add(TokenClass.IDENTIFIER);

        //from Array
        follow.add(TokenClass.OPERATOR_ASSIGNMENT);
        follow.add(TokenClass.OPERATOR_INCREMENT);
        follow.add(TokenClass.OPERATOR_DECREMENT);
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_SEMICOLON);
        follow.add(TokenClass.DELIMITER_OPENING_PARENTHESIS);
        follow.add(TokenClass.DELIMITER_OPENING_SQUARE_BRACKET);

        
        follow.add(TokenClass.IDENTIFIER);
        follow.add(TokenClass.DELIMITER_COMMA);
    }

}
